package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name :DefaultWapper.java
 * @Author : zhouyi
 * @Date : 2015年6月1日
 * @Copyright : 洋码头
 ************************************************************************************/
public class AppDefaultWapper {
	SqlManager manage;

	public AppDefaultWapper() {
		manage = new SqlManager("app" + EnvSetup.getEnv());
	}

	
	/**
	 * 商品搜索
	 * @throws InterruptedException
	 * @param keyword 关键字搜索
	 * @return list
	 * */
	public List<Map> selectProductInApp(String keyword) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<Map> pia = manage.getSelectResults(
				"com.ymttest.database.mapping.AppDefaultMapper.selectProductInApp", keyword);
		return pia;
	}
	/**
	 * 
	 * 直播搜索
	 *@throws InterruptedException
	 *@param CountryGroupId
	 *@param LiveActivityId 
	 *@return list
	 * 
	 * */
	public List<Map> getsLiveActivity(Map m){
		List<Map> liveActivityList = manage.getSelectResults(
				"com.ymttest.database.mapping.AppDefaultMapper.selectLiveBizerByParam", m);
		return liveActivityList;
	}
	
	/**
	 * 
	 * 根据productid 查询app 直播商品catalog id
	 *@throws InterruptedException
	 *@param CountryGroupId
	 *@param LiveActivityId 
	 *@return list
	 * 
	 * */
	public String getCatalogByProId(String productId){
		String catalogId=null;		
		List<Map> catalogList = manage.getSelectResults(
				"com.ymttest.database.mapping.AppDefaultMapper.selectCatalogByProId", productId);
		if (catalogList.size()>0){
			catalogId=(String) catalogList.get(0).get("sCatalogId");
		}		
		return catalogId;
	}
	
	/*根据直播id查询直播截止时间
	 * 
	 * 
	*/
	public List<Map> getActivityTime(String m){
		List<Map> activityTime = manage.getSelectResults("com.ymttest.database.mapping.AppDefaultMapper.selectActivityById", m);
		return activityTime;
	}
	
	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) {
		Map m = new HashMap();
		// 1:北美，2：欧洲，3：亚洲，4：澳新
		m.put("CountryGroupId", 0);
		m.put("LiveActivityId", 0);
		//List<Map> list = new AppDefaultWapper().getsLiveActivity(m);
		//定义一个空数组用来存放查找出来的直播的sellid
		
		
		
		/*final int size = list.size();
		int[] ary = new int[size];
		
				for(int i = 0;i < list.size(); i ++){
					ary[i] = (Integer) list.get(i).get("sellerId");
					Logger.debug(ary[i]);
				}
			*/
		//Logger.debug(new AppDefaultWapper().getCatalogByProId("d9e368ba-f085-436c-a033-c75c5f13bef8"));
		Logger.debug(new AppDefaultWapper().getActivityTime("147468"));
		
	}
}
